package com.pi;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * 对比插件
 */
public class ComparePlugin {


    /**
     * 执行对比
     *
     * @param newVersionDir
     */
    public static List<PatchFile> exec(File newVersionDir, File baseVersionDir) {

        List<File> newFileList = FileUtil.listAllFiles(newVersionDir);

        //比对结果
        List<PatchFile> result = new ArrayList<>();

        for (int i = 0; i < newFileList.size(); i++) {
            File file = newFileList.get(i);

            File baseFile = FileUtil.getBaseFile(file,
                    newVersionDir.getAbsolutePath(), baseVersionDir.getAbsolutePath());

            if ((baseFile != null) && (baseFile.exists())) {
                if (!FileUtil.compare(file, baseFile)) {
                    result.add(new PatchFile(file.getAbsolutePath(), 2));
                }
            } else {
                result.add(new PatchFile(file.getAbsolutePath(), 1));
            }
        }
        return result;
    }
}
